﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Epic.HandyExtensions
{
#pragma warning disable 1591
    public static class FlagTypeExtensions
    {
        #region HasFlag overloads

        public static bool HasFlag(this byte value, byte flag)
        {
            return (value & flag) == flag;
        }
        public static bool HasFlag(this sbyte value, sbyte flag)
        {
            return (value & flag) == flag;
        }

        public static bool HasFlag(this short value, short flag)
        {
            return (value & flag) == flag;
        }
        public static bool HasFlag(this ushort value, ushort flag)
        {
            return (value & flag) == flag;
        }

        public static bool HasFlag(this int value, int flag)
        {
            return (value & flag) == flag;
        }
        public static bool HasFlag(this uint value, uint flag)
        {
            return (value & flag) == flag;
        }

        public static bool HasFlag(this long value, long flag)
        {
            return (value & flag) == flag;
        }
        public static bool HasFlag(this ulong value, ulong flag)
        {
            return (value & flag) == flag;
        }

        #endregion

        public static bool IsFlagType(this Type type)
        {
            if (type.IsEnum) 
                return true;

            if (!type.IsPrimitive) 
                return false;

            if (type == typeof(float) || type == typeof(double))
                return false;

            return true;
        }
    }
}
